﻿using System;

namespace Collaboris.Saf.Definitions
{
    using System.Collections.Generic;

    [Serializable]
    public class SafPropertyDefinition
    {
        private string title;

        private string summary;

        private string example;

        private SafPropertyDefinitionCollection properties;

        private string readMore;

        private string name;

        private Type _underlyingType;

        private string genericTypeFullName;


        private SafClassDefinition classDefinition;

        private Dictionary<string, SafClassDefinition> _genericTypeArguments;

        private SafClassDefinition _genericTypeClassDefinition;

        private Type _genericUnderlyingType;

        private bool renderAsExpression;

        private bool required;

        private string serializedExample;

     private bool outputOnly;

        private string remarks;

        private SafClassDefinition parentClassDefinition;

        private string parentedName;

        private SafPropertyDefinition parentPropertyDefinition;

        public string GenericTypeFullName
        {
            get
            {
                return this.genericTypeFullName;
            }

            set
            {
                this.genericTypeFullName = value;
            }
        }

        public string Title
        {
            get
            {
                return this.title;
            }
            set
            {
                this.title = value;
            }
        }

        public string Summary
        {
            get
            {
                return this.summary;
            }
            set
            {
                this.summary = value;
            }
        }

        public string Example
        {
            get
            {
                return this.example;
            }
            set
            {
                this.example = value;
            }
        }

        public SafPropertyDefinitionCollection Properties
        {
            get
            {
                if (this.properties == null)
                    this.properties = new SafPropertyDefinitionCollection();

                return this.properties;
            }
            set
            {
                this.properties = value;
            }
        }

        public string ReadMore
        {
            get
            {
                return this.readMore;
            }
            set
            {
                this.readMore = value;
            }
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }

        public Type UnderlyingType
        {
            get
            {
                return this._underlyingType;
            }
            set
            {
                this._underlyingType = value;
            }
        }

        public SafClassDefinition ClassDefinition
        {
            get
            {
                return this.classDefinition;
            }
            set
            {
                this.classDefinition = value;
            }
        }

        public Dictionary<string, SafClassDefinition>  GenericTypeArguments
        {
            get
            {
                return this._genericTypeArguments;
            }
            set
            {
                this._genericTypeArguments = value;
            }
        }

        public SafClassDefinition GenericTypeClassDefinition
        {
            get
            {
                return this._genericTypeClassDefinition;
            }
            set
            {
                this._genericTypeClassDefinition = value;
            }
        }

        public Type GenericUnderlyingType
        {
            get
            {
                return this._genericUnderlyingType;
            }
            set
            {
                this._genericUnderlyingType = value;
            }
        }

        public bool IsGeneric
        {
            get
            {
                if (GenericUnderlyingType != null)
                    return true;
                else
                {
                    return false;
                }
            }
            
        }

        public bool RenderAsExpression
        {
            get
            {
                return renderAsExpression;
            }
            set
            {
                renderAsExpression = value;
            }
        }

        public bool Required
        {
            get
            {
                return required;
            }
            set
            {
                required = value;
            }
        }

        public string SerializedExample
        {
            get
            {
                return this.serializedExample;
            }
            set
            {
                this.serializedExample = value;
            }
        }

        public bool OutputProperty
        {
            get
            {
                return this.outputOnly;
            }
            set
            {
                this.outputOnly = value;
            }
        }

        public string Remarks
        {
            get
            {
                return this.remarks;
            }
            set
            {
                this.remarks = value;
            }
        }

        public string ParentedName
        {
            get
            {
                if (this.ParentPropertyDefinition != null && this.ParentPropertyDefinition.Name != "EntityList")
                {
                    this.parentedName = this.ParentPropertyDefinition.Name + "_" + this.Name;
                }
                else
                    this.parentedName = this.Name;
             
                return this.parentedName;
            }
        }

        public SafClassDefinition ParentClassDefinition
        {
            get
            {
                return this.parentClassDefinition;
            }
            set
            {
                this.parentClassDefinition = value;
            }
        }

        public SafPropertyDefinition ParentPropertyDefinition
        {
            get
            {
                return this.parentPropertyDefinition;
            }
            set
            {
                this.parentPropertyDefinition = value;
            }
        }
    }
}